﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;

namespace SharedGenomics.Workbench.Core
{
    public abstract class TaskBase : ITask
    {
        public TaskBase(string name, string displayName, PresenterFactory presenterFactory)
        {
            name.ThrowIfNull("name");
            displayName.ThrowIfNull("displayName");
            presenterFactory.ThrowIfNull("presenterFactory");

            this.Name = name;
            this.DisplayName = displayName;
            this.PresenterFactory = presenterFactory;
        }

        protected IPresenter CreatePresenter(Type presenterType)
        {
            presenterType.ThrowIfNull("presenterType");
            ExceptionHelper.ThrowIf<ArgumentException>(!typeof(IPresenter).IsAssignableFrom(presenterType), "Type must be assignable to IPresenter");

            return this.PresenterFactory.Get(presenterType, true);
        }

        protected virtual void OnCurrentPresenterChanged(EventArgs e)
        {
            this.CurrentPresenterChanged.Raise(this, e);
        }

        private PresenterFactory PresenterFactory { get; set; }

        #region ITask Members

        public abstract IPresenter CurrentPresenter { get; }
        public string Name { get; private set; }
        public string DisplayName { get; private set; }
        public event EventHandler CurrentPresenterChanged;

        #endregion
    }
}
